package demo1;

import java.util.ArrayList;
import java.util.List;

public class Test {
    public static void main(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(1);
        arrayList.add(2);
        arrayList.add(3);
        arrayList.add(4);
        arrayList.add(4,10);
        System.out.println(arrayList);
        //arrayList.add(6,10);//报错，IndexOutOfBoundsException
        ArrayList<Integer> arrayList1 = new ArrayList<>();
        arrayList1.addAll(arrayList);
        System.out.println(arrayList1);
        arrayList1.add(5);
        System.out.println(arrayList);
        System.out.println("===========");
        arrayList.remove(4);
        System.out.println(arrayList);
        System.out.println("===========");
        Integer i = 4;
        arrayList.remove(i);
        System.out.println(arrayList);
        System.out.println("===========");
        System.out.println(arrayList.get(2));
        System.out.println("===========");
        arrayList.set(1,100);
        System.out.println(arrayList);
        System.out.println("===========");
        System.out.println(arrayList.contains(10));
        System.out.println("===========");
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);
        list.add(6);
        list.add(7);
        list.add(8);
        list.add(9);
        list.add(10);
        System.out.println(list);
        List<Integer> sublist = list.subList(2, 7);
        System.out.println(sublist);
        sublist.set(0,100);
        System.out.println(sublist);
        System.out.println(list);
    }
}
